const address = require("../public/address.js");
const brands = require("../public/brands.js");
const source = require("../public/source.js");

module.exports = {
    total: {
        province: 0,
        city: 0,
        county: 0,
        goods: 0,
    },
    all: {
        goodsNames: [],
    },
    // brands: {
    //     series: [],
    //     generation: [],
    //     generationType: []
    // },
    // searchKeyWords: {
    //     store: [],
    // },
    // get storeKeyWords() {
    //     if (!this.searchKeyWords.store.length) {
    //         let store = Array.from(new Set([...source.goods.ram.flat(1), ...source.goods.rom.flat(1)]));
    //         this.searchKeyWords.store = [...store, ...store.map(item => item + "G"), ...store.map(item => item + "GB")];
    //     }
    //     return this.searchKeyWords.store;
    // },
    get baseUrl() {
        return "http://www.hxov.com:7002";
    },
    get provinceTotal() {
        return this.total.province ? this.total.province : address.length;
    },
    get cityTotal() {
        if (!this.total.city) {
            let total = 0;
            address.forEach((pro) => {
                pro.city.forEach(() => total++)
            })
            this.total.city = total;
        }
        return this.total.city;
    },
    get countyTotal() {
        if (!this.total.county) {
            let total = 0;
            address.forEach((pro) => {
                pro.city.forEach((cit) => {
                    cit.county.forEach(() => total++)
                })
            })
            this.total.county = total;
        }
        return this.total.county;
    },
    get goodsTotal() {
        if (!this.total.goods) {
            let total = 0;
            for (let i = 0; i < brands.length; i++) {
                let series = brands[i].series;
                for (let j = 1; j < series.length; j++) {
                    let gene = series[j].generation;
                    let type = series[j].generationType;
                    if(gene){
                        for (let m = 0; m < gene.length; m++) {
                            for (let n = 0; n < type.length; n++) {
                                total++;
                                let spreadName = brands[i].name.toLocaleLowerCase() + series[j].name.toLocaleLowerCase() + gene[m].toLocaleLowerCase() + type[n].toLocaleLowerCase();
                                this.all.goodsNames.push(spreadName);
                            }
                        }
                    }
                }
            }
            this.total.goods = total;
        }
        return this.total.goods;
    },
    get goodsNames() {
        if (!this.all.goodsNames.length) {
            this.goodsTotal();
        }
        return this.all.goodsNames;
    },
    // get brandsInfo() {
    //     if (!this.brands.series.length) {
    //         brands.forEach(brand => {
    //             brand.series.forEach(serie => {
    //                 let gens = serie.generation, genTypes = serie.generationType;
    //                 if (gens) {
    //                     gens.forEach(gen => {
    //                         genTypes.forEach(genType => {
    //                             this.brands.series.push(serie);
    //                             this.brands.gen && this.brands.generation.push(gen);
    //                             this.brands.genType && this.brands.generationType.push(genType);
    //                         })
    //                     })
    //                 }
    //             })
    //         })
    //     }
    //     return this.brands;
    // }
    // get stationTotals() {
    //     if (this.totals.station.length==0) {
    //         let citTotal = this.cityTotal;  //市级门店
    //         let couTotal = this.countyTotal;  //县级门店
    //         let comTotal = couTotal * 1;   //普通门店
    //         this.totals.station = [citTotal, citTotal+couTotal, citTotal+couTotal+comTotal];
    //     }
    //     return this.totals.station;
    // }
};